package com.qingzhuge.autoconfigure;

import com.google.common.collect.Lists;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.stereotype.Component;

import java.util.List;

import static com.qingzhuge.autoconfigure.QingTingProperties.PREFIX;

/**
 * @author : zero.xiao
 * @description :
 * @date : 2018/7/4 0004 上午 10:59
 * @modified :
 * @since :
 */

@Getter
@Setter
@Component
@ConfigurationProperties(prefix = PREFIX)
public class QingTingProperties {
    public static final String PREFIX = "qingting";
    /**
     * 初始化数据
     */
    private boolean initData = false;
    /**初始化用户信息*/
    private boolean initUser = false;
    /**初始化任务计划*/
    private boolean initTask = false;
    /**开启接口*/
    private boolean swagger = false;
    @NestedConfigurationProperty
    private SecurityProperties security = new SecurityProperties();
    @NestedConfigurationProperty
    private Request request = new Request();
    @NestedConfigurationProperty
    private Filter filter = new Filter();
    /**雪花算法配置*/
    @NestedConfigurationProperty
    private DataSource dataSource = new DataSource();
    /**需要加密的配置属性*/
    private List<String> decryptProperties = Lists.newArrayList();

    @Getter
    @Setter
    public static class Request {
        /**恶意请求拦截器允许的最小请求间隔*/
        Integer minRequestIntervalTime = 100;
        /**恶意请求拦截器白名单*/
        private List<String> maliciousRequestWhiteUrls = Lists.newArrayList();
    }

    /**
     * 用于雪花算法id
     */
    @Getter
    @Setter
    public static class DataSource {
        /**机器号 支持的最大机器ID 范围 0-31*/
        Long worid = 1L;
        /**数据源 用于区分机器上不同应用 支持的最大数据标识ID 范围 0-31*/
        Long dataid = 1L;
    }
    /**过滤器*/
    @Getter
    @Setter
    public static class Filter{
        /**开启跨域请求*/
        private boolean cors = true;
        /**开启跨站拦截*/
        private boolean csrf = true;
        /**开启"/api/**"跨域请求*/
        private boolean corsAll = true;
        /**开启跨域请求url:默认开启：/api/sys/open/site，/api/sys/login
         * 如果配置了corsAll=true，同时配置了corsUrls，则覆盖corsAll，开启指定url跨域访问
         * */
        private List<String> corsUrls = Lists.newArrayList();
        /**
         * 跨站请求过滤白名单
         */
        private List<String> csrfWhiteUrls = Lists.newArrayList();
        /**
         * 非法字符过滤白名单
         */
        private List<String> xssWhiteUrls = Lists.newArrayList();
    }
}
